<template>
  <div>
    <h2>User</h2>
    <h2>模版中获取id：{{ $route.params.id }}</h2>
    <h2>代码中获取id:{{ id }}</h2>
  </div>
</template>

<script setup>
import { ref } from "vue";
import { useRoute, onBeforeRouteUpdate } from "vue-router";
const id = ref(0);
const route = useRoute();
id.value = route.params.id;
onBeforeRouteUpdate((to, from) => {
  id.value = to.params.id;
});
</script>

<style lang="scss" scoped>
</style>